package com.tcenter.dao.entities;


import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

import static javax.persistence.GenerationType.IDENTITY;

/**
 *
 */
@Entity
@Table(name = "subject", catalog = "tcenterdb", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
public class Subject implements java.io.Serializable {

    private Integer id;
    private Course course;
    private String name;
    private Set<Task> tasks = new HashSet<Task>(0);


    public Subject() {
    }

    public Subject(String name) {
        this.name = name;
    }

    public Subject(String name, Course course) {
        this.name = name;
        this.course = course;
    }


    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "course_id")
    public Course getCourse() {
        return this.course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }

    @Column(name = "name", unique = true, nullable = false, length = 15)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "subject")
    public Set<Task> getTasks() {
        return this.tasks;
    }

    public void setTasks(Set<Task> tasks) {
        this.tasks = tasks;
    }

}
